const BaseHandler     = require('../base-handler');
const HTTP_VERBS      = require('../../../constants').HTTP_VERBS;

class FetchDianpingHandler extends BaseHandler {

    get pattern() {
        return '/walls/:wall_id/fetch_dianping';
    }

    doGET(request, response) {
        var me = this;
        if(!request.session.user.authenticated) {
            response.redirect('/login?ref=expired');
        } else {
            var userId = request.session.user.id;
            var shopId = request.query.shop_id;
            if (!shopId) {
                return response.json({
                    success: false,
                    error: '请提大众点评店铺编号[shop_id]!'
                });
            }

            this.Controller.fetchDianpingReviewsData(request.params.wall_id, userId, shopId, request.headers['host'], (result) => {
                response.json(result);
            });
        }
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = FetchDianpingHandler;